﻿var refreshGirdData;
var bootstrap = function ($, learun) {
    "use strict";

    var userinfo;
    var _url = config.base_server() + 'fileinfos/list';
    var tabType = 'releaseFile';
    var wfType = '1';
    var folderId = "0";
    var folderAuth = '';

    //1 查看 2上传 3 下载  4 删除  5 复原
    var btnName = {
        '1': '查看',
        '3': '下载',
        '4': '删除',
        '5': '复原',
        '6': '彻底删除'
    }

    var page = {
        init: function () {
            $(".lr-tab-content").height($(window).height() - 205);
            $(".lr-tab-content").css("margin-top", 205 - $(window).height());
            //$("#verifyFile").css("padding","5px 8px;")
            page.initleft();
            page.initGrid();
            page.bind();
            userinfo = learun.clientdata.get(['userinfo']);
        },
        bind: function () {
            // 搜索框初始化
            $('#txt_Keyword').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var $this = $(this);
                    var keyword = $this.val();
                    page.search[tabType]({keyword: keyword});
                }
            });
            $('#lr_form_tabs').lrFormTab(function (id) {
                wfType = id;
                page.search.verifyFile && page.search.verifyFile();
            });
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search[tabType]({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });

            //上传文件
            $('#lr_upload').on('click', function () {
                learun.layerForm({
                    id: 'UploadifyForm',
                    title: '上传文件',
                    url: config.webportal_server + 'pages/system/files/uploadifyForm.html?folderId=' + folderId + '&access_token=' + config.getToken().access_token,
                    width: 600,
                    height: 400,
                    btn: null,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            //发布文件
            $('#lr_publish').on('click', function () {
                if (config.isTabs()) { //主题1
                    top.learun.frameTab.open({
                        id: '5456a5f791844dbaaa1474af2a70e8db',
                        css: 'fa magic',
                        name: '发布文件',
                        path: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=5456a5f791844dbaaa1474af2a70e8db&type=0&access_token=' + config.getToken().access_token,
                    });
                } else {
                    top.learun.layerForm({
                        id: '5456a5f791844dbaaa1474af2a70e8db',
                        title: '发布文件',
                        url: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=5456a5f791844dbaaa1474af2a70e8db&type=0&access_token=' + config.getToken().access_token,
                        height: 1080,
                        width: 1920
                    });
                }
            });
            //新建文件夹
            $('#lr_mkdir').on('click', function () {
                learun.layerForm({
                    id: 'FolderForm',
                    title: '添加文件夹',
                    url: config.webportal_server + 'pages/system/files/folderForm.html?parentId=' + folderId + '&access_token=' + config.getToken().access_token,
                    width: 400,
                    height: 200,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            //文件下载
            $('#lr_download').on('click', function () {
                var keyValue = $("#gridTable").jfGridValue("id");
                var fileType = $("#gridTable").jfGridValue("type");
                if (keyValue) {
                    if (fileType != 'folder') {
                        learun.download({
                            url: config.base_server() + 'fileinfos/download?id=' + keyValue + '&access_token=' + config.getToken().access_token,
                            param: {keyValue: keyValue},
                            method: 'POST'
                        });
                    } else {
                        learun.alert.error('目前不支持文件夹下载');
                    }
                } else {
                    learun.alert.warning('请选择要下载的文件！');
                }
            });
            //文件预览
            $('#lr_preview').on('click', function () {
                var keyValue = $("#gridTable").jfGridValue("id");
                var fileType = $("#gridTable").jfGridValue("type");
                if (keyValue) {
                    if (fileType != 'folder') {
                        learun.layerForm({
                            id: 'PreviewForm',
                            title: '文件预览',
                            url: config.webportal_server + 'pages/utility/previewFile.html?keyVaule=' + keyValue + '&access_token=' + config.getToken().access_token,
                            width: 1080,
                            height: 850,
                            btn: null,
                            callBack: function (id) {
                                return top[id].acceptClick(refreshGirdData);
                            }
                        });
                    } else {
                        learun.alert.error('请选择文件');
                    }
                } else {
                    learun.alert.warning('请选择要预览的文件！');
                }
            });
            //文件（夹）删除
            $('#lr_delete').on('click', function () {
                var keyValue = $("#gridTable").jfGridValue("id");
                var fileType = $("#gridTable").jfGridValue("type");
                if(fileType!='folder'){
                    return;
                }
                if (keyValue) {
                    learun.layerConfirm("注：您确定要删除此" + (fileType == "folder" ? "文件夹" : "文件") + "吗？可在回收站还原！", function (res) {
                        if (res) {
                            learun.postForm(config.base_server() + 'fileinfos/delete/' + keyValue + '?fileType=' + fileType + '&access_token=' + config.getToken().access_token, {
                                keyValue: keyValue,
                                fileType: fileType
                            }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                } else {
                    learun.alert.warning('请选择要删除的文件夹或文件！');
                }
            });
            //文件授权
            $('#lr_share').on('click', function () {
                var keyValue = $("#gridTable").jfGridValue("id");
                var fileType = $("#gridTable").jfGridValue("type");
                var createUserid = $("#gridTable").jfGridValue("createUserid");

                if(createUserid!=userinfo.user.id){
                    learun.alert.error('您无权分享，请联系管理员');
                    return;
                }
                // if (fileType == 'folder') {
                //     learun.alert.error('请选择要授权的文件');
                //     return;
                // }
                if (keyValue) {
                    learun.layerForm({
                        id: 'fileshare',
                        title: '文件共享',
                        url: config.webportal_server + 'pages/system/files/share.html?keyValue=' + keyValue + '&fileType=' + fileType + '&access_token=' + config.getToken().access_token,
                        width: 750,
                        height: 500,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                } else {
                    learun.alert.warning('请选择要共享的文件夹或文件！');
                }
            });
            //取消共享
            $('#lr_cancelshare').on('click', function () {
                var keyValue = $("#gridTable").jfGridValue("id");
                var fileType = $("#gridTable").jfGridValue("type");
                if (keyValue) {
                    learun.layerConfirm("注：您确定要取消共享此" + (fileType == "folder" ? "文件夹" : "文件") + "吗？", function (res) {
                        if (res) {
                            learun.postForm(config.base_server() + 'fileinfos/share/' + keyValue + '?isShare=0&fileType=' + fileType + '&access_token=' + config.getToken().access_token, {
                                isShare: 0,
                                fileType: fileType
                            }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                } else {
                    learun.alert.warning('请选择要取消共享的文件夹或文件！');
                }
            });
            //文件（夹）重命名
            $('#lr_rename').on('click', function () {
                var keyValue = $("#gridTable").jfGridValue("id");
                var fileType = $("#gridTable").jfGridValue("type");
                if (keyValue) {
                    learun.layerForm({
                        id: (fileType == "folder" ? "FolderForm" : "FileForm"),
                        title: (fileType == "folder" ? "文件夹" : "文件") + '重命名',
                        url: config.webportal_server + 'pages/system/files/' + (fileType == "folder" ? "folderForm.html" : "fileForm.html") + '?keyValue=' + keyValue + '&access_token=' + config.getToken().access_token,
                        width: 400,
                        height: 200,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                } else {
                    learun.alert.warning('请选择要重命名的文件夹或文件！');
                }
            });
            //文件（夹）移动
            $('#lr_move').on('click', function () {
                var keyValue = $("#gridTable").jfGridValue("id");
                var fileType = $("#gridTable").jfGridValue("type");
                if (keyValue) {
                    learun.layerForm({
                        id: 'MoveLocation',
                        title: (fileType == "folder" ? "文件夹" : "文件") + '移动',
                        url: config.webportal_server + 'pages/system/files/moveForm.html?keyValue=' + keyValue + "&fileType=" + fileType + '&access_token=' + config.getToken().access_token,
                        width: 400,
                        height: 350,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                } else {
                    learun.alert.warning('请选择要移动的文件夹或文件！');
                }
            });
            //文件（夹）还原
            $('#lr_restoreFile').on('click', function () {
                var keyValue = $("#gridTable").jfGridValue("id");
                var fileType = $("#gridTable").jfGridValue("type");
                if (keyValue) {
                    learun.layerConfirm("注：您确定要还原此" + (fileType == "folder" ? "文件夹" : "文件") + "吗？", function (res) {
                        if (res) {
                            learun.postForm(config.base_server() + 'fileinfos/restore/' + keyValue + '?fileType=' + fileType + '&access_token=' + config.getToken().access_token, {
                                fileType: fileType
                            }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                } else {
                    learun.alert.warning('请选择要还原的文件夹或文件！');
                }
            });
            //文件（夹）彻底删除
            $('#lr_thoroughDelete').on('click', function () {
                var keyValue = $("#gridTable").jfGridValue("id");
                var fileType = $("#gridTable").jfGridValue("type");
                if (keyValue) {
                    learun.layerConfirm("注：您确定要删除此" + (fileType == "folder" ? "文件夹" : "文件") + "吗？该操作将无法恢复！", function (res) {
                        if (res) {
                            learun.postForm(config.base_server() + 'fileinfos/thoroughDelete/' + keyValue + '?fileType=' + fileType + '&access_token=' + config.getToken().access_token, {
                                fileType: fileType
                            }, function () {
                                refreshGirdData();
                            });
                        }
                    });
                } else {
                    learun.alert.warning('请选择要删除的文件夹或文件！');
                }
            });
            //清空回收站
            $('#lr_emptyRecycled').on('click', function () {
                learun.layerConfirm("注：您确定要清空回收站吗？该操作将无法恢复！", function (res) {
                    if (res) {
                        learun.postForm(config.base_server() + 'fileinfos/emptyRecycled?access_token=' + config.getToken().access_token, {}, function () {
                            refreshGirdData();
                        });
                    }
                });
            });
            $('#pathList').on('click', '.path-item', function () {
                var $this = $(this);
                var data = $this[0]._data;
                if (data) {
                    folderAuth = data.authType;
                }
                $this.nextAll().remove();
                folderId = $this.attr('data-fileid');
                page.openFolder();
            });
        },
        initleft: function () {
            $('#lr_left_list li').on('click', function () {
                var $this = $(this);
                $this.parent().find('.active').removeClass('active');
                $this.addClass('active');

                var v = $this.attr('data-value');
                $('.lr-layout-body>.active').removeClass('active');
                $('#' + v).addClass('active');
                tabType = v;
                page.search[v] && page.search[v]();



                if(v=='releaseFile'){
                    $('#titleinfo').text("正式文件");
                    $(".btn-group").show();
                }else  if(v=='recycledFile'){
                    $('#titleinfo').text("回收站");
                    $(".btn-group").show();
                }else {
                    $('#titleinfo').text("审核中文件");
                    $(".btn-group").hide();
                }
            });
        },
        //加载表格
        initGrid: function () {
            $('#wfgridtable').jfGrid({
                url: config.base_server() + 'fileinfos/tasks?access_token=' + config.getToken().access_token,
                headData: [
                    {
                        label: "任务", name: "taskName", width: 160, align: "left",
                        formatter: function (cellvalue, row, dfop, $cell) {
                            if (row.status == 3) {
                                if (wfType == '1') {
                                    return '本人发起';
                                } else {
                                    cellvalue;
                                }
                            }

                            var isaAain = false;
                            if (wfType == '1') {
                                if (row.isAgain == 1) {
                                    isaAain = true;
                                } else if (row.isFinished == 0) {
                                    if(row.status == -1){
                                        isaAain = true;
                                    } else {
                                        // 加入撤销按钮
                                        $cell.on('click', '.revoke', function () {// 删除
                                            learun.layerConfirm('是否确认撤销流程？', function (res, _index) {
                                                if (res) {

                                                    learun.loading(true, '撤销流程...');
                                                    var postData = {
                                                        processId: row.id,
                                                    };
                                                    learun.httpAsync('Post', config.base_server() + 'wftasks/revoke/' + row.id + '?access_token=' + config.getToken().access_token, postData, function (data) {
                                                        learun.loading(false);
                                                        refreshGirdData();
                                                    });
                                                    top.layer.close(_index);
                                                }
                                            });
                                            return false;
                                        });
                                        var _btnHtml = '本人发起';
                                        if (row.status == 1 && row.isStart == 0) {
                                            _btnHtml += '<span class="label label-warning revoke" style="margin-left:5px;" title="撤销流程" >撤销流程</span>';
                                        }
                                        return _btnHtml;
                                    }
                                } else {
                                    return '本人发起';
                                }
                            }
                            if (row.taskType == 3) {
                                return "【加签】" + cellvalue;
                            } else if (row.taskType == 5 && wfType == '2') {
                                isaAain = true;
                            } else if (row.taskType == 5) {
                                return '重新发起';
                            }

                            if (isaAain) {
                                $cell.on('click', '.AgainCreate', function () {
                                    var title = "";
                                    if (row.schemeName != row.title && row.title) {
                                        title = row.schemeName + "(" + row.title + ")";
                                    } else {
                                        title = row.schemeName;
                                    }

                                    if (config.isTabs()) { //主题1
                                        top.learun.frameTab.open({
                                            id: row.id,
                                            css: 'fa magic',
                                            name: '重新发起-' + title,
                                            path: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=' + row.id + '&processId=' + row.id + '&type=2&access_token=' + config.getToken().access_token,
                                        });
                                    } else {
                                        top.learun.layerForm({
                                            id: row.id,
                                            title: '重新发起-' + title,
                                            url: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=' + row.id + '&processId=' + row.id + '&type=2&access_token=' + config.getToken().access_token,
                                            height: 1080,
                                            width: 1920
                                        });
                                    }

                                    return false;
                                });
                                return '<span class="label label-danger AgainCreate" title="重新发起">重新发起</span>';
                            }


                            if (wfType == '3' && row.taskType == 1 && row.isFinished == 0 && row.canRevoke == 1) {// 未完成任务，添加一个撤销按钮
                                cellvalue = '<span class="label label-warning revoke2" style="margin-left:5px;margin-right:5px;" title="撤销审核" >撤销审核</span>' + cellvalue;

                                $cell.on('click', '.revoke2', function () {// 删除
                                    learun.layerConfirm('是否确认撤销审核？', function (res, _index) {
                                        if (res) {

                                            learun.loading(true, '撤销审核...');
                                            var postData = {
                                                processId: row.id,
                                                taskId: row.taskId,
                                            };
                                            learun.httpAsync('Post', config.base_server() + 'wfengines/revokeAudit?access_token=' + config.getToken().access_token, postData, function (data) {
                                                learun.loading(false);
                                                refreshGirdData();
                                            });

                                            top.layer.close(_index);
                                        }
                                    });
                                    return false;
                                });
                            }

                            return cellvalue;
                        }
                    },
                    {label: "文件描述", name: "name", width: 200, align: "left"},
                    {label: "流程单号", name: "code", width: 120, align: "center"},
                    {
                        label: "等级", name: "processLevel", width: 80, align: "center",
                        formatter: function (cellvalue) {
                            switch (cellvalue) {
                                case 0:
                                    return '普通';
                                    break;
                                case 1:
                                    return '重要';
                                    break;
                                case 2:
                                    return '紧急';
                                    break;
                            }
                        }
                    },
                    {
                        label: "状态", name: "status", width: 70, align: "center",
                        formatter: function (cellvalue, row) {
                            if (row.isFinished == 0) {
                                if (cellvalue == 1) {
                                    return "<span class=\"label label-success\">运行中</span>";
                                } else if (cellvalue == -1) {
                                    return "<span class=\"label label-default\">草稿</span>";
                                }
                            } else {
                                return "<span class=\"label label-warning\">结束</span>";
                            }

                        }
                    },
                    {label: "发起者", name: "createUsername", width: 70, align: "center"},
                    {
                        label: "申请时间", name: "createTime", width: 150, align: "left",
                        formatter: function (cellvalue) {
                            return learun.formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
                        }
                    }
                ],
                mainId: 'id',
                isPage: true,
                sidx: 'create_time DESC',
                onSelectRow: function (row) {
                    if (wfType == '2') {
                        if (row.taskType == 5) {
                            $('#lr_verify span').text("重新发起");
                        } else if (row.taskType == 3) {
                            $('#lr_verify span').text("【加签】" + row.taskName);
                        } else {
                            $('#lr_verify span').text(row.taskName);
                        }
                    }
                },
                dblclick: function () {
                    if (wfType == '2') {
                        page.verify();
                    } else {
                        page.eye();
                    }
                }
            });

            $('#gridTable').jfGrid({
                url: config.base_server() + 'fileinfos/list?access_token=' + config.getToken().access_token,
                headData: [
                    {
                        label: '文件描述', name: 'name', width: 400, align: 'left',
                        formatter: function (cellvalue, options, rowObject) {
                            if (options.length != 0) {
                                return "<div style='cursor:pointer;'><div style='float: left;'><img src='/assets/plugins/images/filetype/" + options.ext + ".png' style='width:30px;height:30px;padding:5px;margin-left:-5px;margin-right:5px;' /></div><div style='float: left;line-height:35px;'>" + options.name + "</div></div>";
                            }
                        }
                    },
                    {
                        label: '大小', name: 'size', width: 100, align: 'center',
                        formatter: function (cellvalue, row) {
                            if (row.type == 'folder') {
                                return '';
                            } else {
                                return page.CountFileSize(cellvalue);
                            }
                        }
                    },
                    {
                        label: '创建人', name: 'createUserid', width: 1, align: 'center',hidden: true
                    },
                    {
                        label: '操作', name: 'id', width: 200, align: 'left',
                        formatter: function (value, row, op, $cell) {
                            var $div = $('<div></div>');
                            if (row.type == 'folder') {
                                var $openFolder = $('<span class=\"label label-success\" style=\"cursor: pointer;\">打开</span>');
                                $openFolder.on('click', function () {
                                    folderId = value;
                                    folderAuth = row.authType;
                                    page.openFolder();
                                    var $span = $('<span data-fileid="' + value + '"  class="path-item">/&nbsp;' + row.name + '</span>');
                                    $span[0]._data = row;
                                    $('#pathList').append($span);
                                });
                                $div.append($openFolder);
                            } else {
                                var btnlist = row.authType.split(',');
                                $.each(btnlist, function (_index, _item) {
                                    if (_item != '6' && _item != '5' && $div.find('[data-value="' + _item + '"]').length == 0) {
                                        var btnClass = 'label-info';
                                        if (_item == '4') {
                                            btnClass = 'label-warning';
                                        }
                                        var $btn = $('<span class=\"label ' + btnClass + '\" data-value="' + _item + '" style=\"cursor: pointer; margin-right:8px;\">' + btnName[_item] + '</span>');
                                        $btn[0]._row = row;
                                        $btn.on('click', function () {
                                            var $this = $(this);
                                            var btnValue = $this.attr('data-value');
                                            var btnRow = $this[0]._row;
                                            switch (btnValue) {
                                                case '1':// 查看
                                                    learun.layerForm({
                                                        id: 'PreviewForm',
                                                        title: '文件预览',
                                                        url: config.webportal_server + 'pages/utility/previewFile.html?keyVaule=' + btnRow.id + '&access_token=' + config.getToken().access_token,
                                                        width: 1080,
                                                        height: 850,
                                                        btn: null
                                                    });
                                                    break;
                                                case '3':// 下载
                                                    learun.download({
                                                        url: config.base_server() + 'fileinfos/download?id=' + btnRow.id + '&access_token=' + config.getToken().access_token,
                                                        param: {},
                                                        method: 'POST'
                                                    });
                                                    break;
                                                case '4':// 删除
                                                    learun.layerConfirm('是否确认删除该文件！', function (res) {
                                                        if (res) {
                                                            learun.postForm(config.base_server() + 'fileinfos/delete/' + btnRow.id + '?fileType=&access_token=' + config.getToken().access_token, {
                                                                fileType: ''
                                                            }, function () {
                                                                refreshGirdData();
                                                            });
                                                        }
                                                    });
                                                    break;
                                            }
                                        });
                                        $div.append($btn);
                                    }
                                });
                            }
                            return $div;
                        }
                    }
                ],
                dblclick: function (id) {
                    var rowData = $('#gridTable').jfGridGet('rowdata');
                    if (rowData.type == "folder") {
                        folderId = rowData.id;
                        folderAuth = rowData.authType;
                        page.openFolder();
                        var $span = $('<span data-fileid="' + folderId + '"  class="path-item">/&nbsp;' + rowData.name + '</span>');
                        $span[0]._data = rowData;
                        $('#pathList').append($span);
                    }
                },
                mainId: 'id'
            });

            $('#dgridtable').jfGrid({
                url: config.base_server() + 'fileinfos/recycledList?access_token=' + config.getToken().access_token,
                headData: [
                    {
                        label: '文件描述', name: 'name', width: 400, align: 'left',
                        formatter: function (cellvalue, options, rowObject) {
                            if (options.length != 0) {
                                return "<div style='cursor:pointer;'><div style='float: left;'><img src='/assets/plugins/images/filetype/" + options.ext + ".png' style='width:30px;height:30px;padding:5px;margin-left:-5px;margin-right:5px;' /></div><div style='float: left;line-height:35px;'>" + options.name + "</div></div>";
                            }
                        }
                    },
                    {
                        label: '大小', name: 'size', width: 100, align: 'center',
                        formatter: function (cellvalue) {
                            return page.CountFileSize(cellvalue);
                        }
                    },
                    {
                        label: '操作', name: 'id', width: 200, align: 'left',
                        formatter: function (value, row, op, $cell) {
                            var $div = $('<div></div>');
                            var btnlist = row.authType.split(',');
                            $.each(btnlist, function (_index, _item) {
                                if (_item != '2' && _item != '4' && $div.find('[data-value="' + _item + '"]').length == 0) {
                                    var btnClass = 'label-info';
                                    if (_item == '6') {
                                        btnClass = 'label-danger';
                                    } else if (_item == '5') {
                                        btnClass = 'label-warning';
                                    }
                                    var $btn = $('<span class=\"label ' + btnClass + '\" data-value="' + _item + '" style=\"cursor: pointer; margin-right:8px;\">' + btnName[_item] + '</span>');
                                    $btn[0]._row = row;
                                    $btn.on('click', function () {
                                        var $this = $(this);
                                        var btnValue = $this.attr('data-value');
                                        var btnRow = $this[0]._row;
                                        switch (btnValue) {
                                            case '1':// 查看
                                                learun.layerForm({
                                                    id: 'PreviewForm',
                                                    title: '文件预览',
                                                    url: config.webportal_server + 'pages/utility/previewFile.html?keyVaule=' + btnRow.id + '&access_token=' + config.getToken().access_token,
                                                    width: 1080,
                                                    height: 850,
                                                    btn: null
                                                });
                                                break;
                                            case '3':// 下载
                                                learun.download({
                                                    url: config.base_server() + 'fileinfos/download?id=' + btnRow.id + '&access_token=' + config.getToken().access_token,
                                                    param: {},
                                                    method: 'POST'
                                                });
                                                break;
                                            case '5':// 复原
                                                learun.layerConfirm('是否确认还原该文件！', function (res) {
                                                    if (res) {
                                                        learun.postForm(config.base_server() + 'fileinfos/restore/' + btnRow.id + '?fileType=&access_token=' + config.getToken().access_token, {
                                                            fileType: ''
                                                        }, function () {
                                                            refreshGirdData();
                                                        });
                                                    }
                                                });
                                                break;
                                            case '6':// 彻底删除
                                                learun.layerConfirm('是否确认彻底删除该文件！', function (res) {
                                                    if (res) {
                                                        learun.postForm(config.base_server() + 'fileinfos/thoroughDelete/' + btnRow.id + '?fileType=&access_token=' + config.getToken().access_token, {
                                                            fileType: ''
                                                        }, function () {
                                                            refreshGirdData();
                                                        });
                                                    }
                                                });
                                                break;
                                        }
                                    });
                                    $div.append($btn);
                                }
                            });
                            return $div;
                        }
                    }
                ],
                mainId: 'id'
            });

            page.search.releaseFile();
        },
        search: {
            verifyFile: function (param) {
                param = param || {};
                param.categoryId = wfType;
                $('#wfgridtable').jfGridSet('reload', param);
            },
            releaseFile: function (param) {
                param = param || {};
                param.folderId = folderId || "0";

                if (param.folderId == "0") {
                    $('#pathList [data-fileid="0"]').nextAll().remove();
                }

                $('#gridTable').jfGridSet('reload', param);
            },
            recycledFile: function (param) {
                param = param || {};
                $('#dgridtable').jfGridSet('reload', param);
            }
        },
        search2: {
            verifyFile: function () {
                $('#wfgridtable').jfGridSet('reload');
            },
            releaseFile: function () {
                $('#gridTable').jfGridSet('reload');
            },
            recycledFile: function () {
                $('#dgridtable').jfGridSet('reload');
            }
        },
        verify: function () {
            var processId = $('#wfgridtable').jfGridValue('id');
            var taskId = $('#wfgridtable').jfGridValue('taskId');
            var title = $('#wfgridtable').jfGridValue('title');
            var schemeName = $('#wfgridtable').jfGridValue('schemeName');
            var taskName = $('#wfgridtable').jfGridValue('taskName');
            var taskType = $('#wfgridtable').jfGridValue('taskType');

            if (schemeName != title && title) {
                title = schemeName + "(" + title + ")";
            } else {
                title = schemeName;
            }

            //1审批2传阅3加签4子流程5重新创建
            switch (taskType) {
                case 1:// 审批
                    if (config.isTabs()) { //主题1
                        top.learun.frameTab.open({
                            id: taskId,
                            css: 'fa magic',
                            name: '审批-' + title + '/' + taskName,
                            path: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=' + processId + taskId + '&processId=' + processId + '&taskId=' + taskId + '&type=100&access_token=' + config.getToken().access_token,
                        });
                    } else {
                        learun.layerForm({
                            id: taskId,
                            title: '审批-' + title + '/' + taskName,
                            url: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=' + processId + taskId + '&processId=' + processId + '&taskId=' + taskId + '&type=100&access_token=' + config.getToken().access_token,
                            height: 1080,
                            width: 1920
                        });
                    }
                    break;
                case 2:// 传阅
                    if (config.isTabs()) { //主题1
                        top.learun.frameTab.open({
                            id: taskId,
                            css: 'fa magic',
                            name: '查阅-' + title + '/' + taskName,
                            path: '/LR_NewWorkFlow/NWFProcess/NWFContainerForm?tabIframeId=' + taskId + '&type=refer' + "&processId=" + processId + "&taskId=" + taskId,
                        });
                    } else {
                        learun.layerForm({
                            id: taskId,
                            title: '查阅-' + title + '/' + taskName,
                            url: '/LR_NewWorkFlow/NWFProcess/NWFContainerForm?tabIframeId=' + taskId + '&type=refer' + "&processId=" + processId + "&taskId=" + taskId,
                            height: 1080,
                            width: 1920
                        });
                    }
                    break;
                case 3:// 加签
                    if (config.isTabs()) { //主题1
                        top.learun.frameTab.open({
                            id: taskId,
                            css: 'fa magic',
                            name: '加签审核-' + title + '/' + taskName,
                            path: '/LR_NewWorkFlow/NWFProcess/NWFContainerForm?tabIframeId=' + taskId + '&type=signAudit' + "&processId=" + processId + "&taskId=" + taskId,
                        });
                    } else {
                        learun.layerForm({
                            id: taskId,
                            title: '加签审核-' + title + '/' + taskName,
                            url: '/LR_NewWorkFlow/NWFProcess/NWFContainerForm?tabIframeId=' + taskId + '&type=signAudit' + "&processId=" + processId + "&taskId=" + taskId,
                            height: 1080,
                            width: 1920
                        });
                    }
                    break;
                case 5:// 重新创建
                    if (config.isTabs()) { //主题1
                        top.learun.frameTab.open({
                            id: processId,
                            css: 'fa magic',
                            name: '重新发起-' + title,
                            path: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=' + processId + '&processId=' + processId + '&taskId=' + taskId + '&type=1&access_token=' + config.getToken().access_token,
                        });
                    } else {
                        learun.layerForm({
                            id: processId,
                            title: '重新发起-' + title,
                            url: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=' + processId + '&processId=' + processId + '&taskId=' + taskId + '&type=1&access_token=' + config.getToken().access_token,
                            height: 1080,
                            width: 1920
                        });
                    }
                    break;
            }
        },
        eye: function () {
            var processId = $('#wfgridtable').jfGridValue('id') || '';
            var taskId = $('#wfgridtable').jfGridValue('taskId') || '';
            var title = $('#wfgridtable').jfGridValue('name');
            var taskType = $('#wfgridtable').jfGridValue('taskType');


            var enabledMark = $('#wfgridtable').jfGridValue('status');
            if (enabledMark == 2) {
                learun.alert.warning("草稿不能查看进度");
                return;
            }
            if (learun.checkrow(processId)) {
                if (taskType == '4' || taskType == '6') {
                    if (config.isTabs()) { //主题1
                        learun.frameTab.open({
                            id: processId + taskId,
                            css: 'fa magic',
                            name: '查看流程进度【' + title + '】',
                            path: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=' + processId + taskId + '&processId=' + processId + '&taskId=' + taskId + '&type=100&access_token=' + config.getToken().access_token
                        });
                    } else {
                        learun.layerForm({
                            id: processId,
                            title: '查看流程进度【' + title + '】',
                            url: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=' + processId + taskId + '&processId=' + processId + '&taskId=' + taskId + '&type=100&access_token=' + config.getToken().access_token,
                            height: 1080,
                            width: 1920
                        });
                    }
                } else {
                    if (config.isTabs()) { //主题1
                        learun.frameTab.open({
                            id: processId + taskId,
                            css: 'fa magic',
                            name: '查看流程进度【' + title + '】',
                            path: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=' + processId + taskId + '&processId=' + processId + '&taskId=' + taskId + '&type=100&access_token=' + config.getToken().access_token
                        });
                    } else {
                        learun.layerForm({
                            id: processId,
                            title: '查看流程进度【' + title + '】',
                            url: config.webportal_server + 'pages/workflow/wfmyTask/custmerWorkFlowForm.html?shcemeCode=bill_uploadfile&tabIframeId=' + processId + taskId + '&processId=' + processId + '&taskId=' + taskId + '&type=100&access_token=' + config.getToken().access_token,
                            height: 1080,
                            width: 1920
                        });
                    }
                }
            }
        },

        openFolder: function () {
            page.search.releaseFile();
        },

        //计算文件大小函数(保留两位小数),Size为字节大小
        CountFileSize: function (Size) {
            var m_strSize = "";
            var FactSize = 0;
            FactSize = Size;
            if (FactSize < 1024.00)
                m_strSize = page.ToDecimal(FactSize) + " 字节";
            else if (FactSize >= 1024.00 && FactSize < 1048576)
                m_strSize = page.ToDecimal(FactSize / 1024.00) + " KB";
            else if (FactSize >= 1048576 && FactSize < 1073741824)
                m_strSize = page.ToDecimal(FactSize / 1024.00 / 1024.00) + " MB";
            else if (FactSize >= 1073741824)
                m_strSize = page.ToDecimal(FactSize / 1024.00 / 1024.00 / 1024.00) + " GB";
            return m_strSize;
        },
        //保留两位小数
        //功能：将浮点数四舍五入，取小数点后2位
        ToDecimal: function (x) {
            var f = parseFloat(x);
            if (isNaN(f)) {
                return 0;
            }
            f = Math.round(x * 100) / 100;
            return f;
        },


    };

    refreshGirdData = function () {
        page.search2[tabType]();
    };

    page.init();
}
